class MyCircularQueue {
    arr: (number|null)[]
    start: number
    end: number
    length: number
    constructor(k: number) {
        this.arr = Array(k).fill(null)
        this.start = 0
        this.length = 0
        this.end = -1
    }

    enQueue(value: number): boolean {

        if(this.length < this.arr.length) {
            this.end = ++this.end >= this.arr.length ? 0 : this.end
            this.arr[this.end] = value
            this.length++
            console.log(this.arr)
            return true
        }else{
            console.log(this.arr)
            return false
        }
    }

    deQueue(): boolean {
        if(this.length > 0) {
            this.arr[this.start] = null
            this.start = ++this.start >= this.arr.length ? 0 : this.start
            this.length--
            console.log(this.arr)
            return true
        }else{
            console.log(this.arr)
            return false

        }
    }

    Front(): number {
        if(this.length != 0){
            console.log(this.arr)
            return this.arr[this.start] as number
        }else{
            console.log(this.arr)
            return -1
        }
    }

    Rear(): number {
        if(this.length != 0){
            return this.arr[this.end] as number
        }else{
            return -1
        }
    }

    isEmpty(): boolean {
        return this.length === 0
    }

    isFull(): boolean {
        return this.length === this.arr.length
    }
}

/**
 * Your MyCircularQueue object will be instantiated and called as such:
 * var obj = new MyCircularQueue(k)
 * var param_1 = obj.enQueue(value)
 * var param_2 = obj.deQueue()
 * var param_3 = obj.Front()
 * var param_4 = obj.Rear()
 * var param_5 = obj.isEmpty()
 * var param_6 = obj.isFull()
 */
 let circularQueue = new MyCircularQueue(3); // 设置长度为 3
 console.log(circularQueue.enQueue(2))
 console.log(circularQueue.Rear())// 返回 3
 console.log(circularQueue.Front())// 返回 3
 console.log(circularQueue.deQueue())// 返回 true
 console.log(circularQueue.Front())// 返回 3
 console.log(circularQueue.deQueue())// 返回 true
 console.log(circularQueue.Front())// 返回 3
 console.log(circularQueue.enQueue(4))// 返回 true
 console.log(circularQueue.enQueue(2))// 返回 true
 console.log(circularQueue.enQueue(2))
 console.log(circularQueue.enQueue(3))
//  console.log(circularQueue.isFull())// 返回 true
//  console.log(circularQueue.isEmpty())// 返回 true
//  console.log(circularQueue.enQueue(4))// 返回 true
//  console.log(circularQueue.Rear())// 返回 4
 